<template>
  <div class="pos-desc">
    <p class="detail-title">
      职位描述<span class="btn" v-if="showView" @click="toggleView">编辑</span>
    </p>
    <div class="com-container" v-if="showView">
      <div class="desc">
        <div class="desc-container">
          <p class="desc-title">职责描述：</p>
          <div class="desc-content">
            <p v-html="posInfo.duty"></p>
          </div>
          <p class="pos-title">岗位要求：</p>
          <div class="pos-content">
            <p v-html="posInfo.request"></p>
          </div>
        </div>
      </div>
    </div>
    <div class="com-form" v-else>
      <div class="postForm">
        <div class="form-item">
          <div class="text" required>职责描述:</div>
          <div class="textarea">
            <textarea v-model="posInfo.duty" placeholder="请输入职责描述" />
          </div>
        </div>
        <div class="form-item">
          <div class="text" required>岗位要求:</div>
          <div class="textarea">
            <textarea v-model="posInfo.request" placeholder="请输入岗位要求" />
          </div>
        </div>
        <div class="submit">
          <button class="confirm" type="button" @click="submit">保存</button>
          <button class="cancel" type="button" @click="cancel">取消</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  props: ['info'],
  data () {
    return {
      posInfo: {
        duty: '',
        request: ''
      },
      showView: true,
    }
  },
  watch: {
    info (val) {
      this.posInfo = val;
      this.toCheck();
    }
  },
  created () {
    this.posInfo = this.info;
  },
  mounted () {
  },
  computed: {
  },
  methods: {
    toCheck () {
      this.posInfo = {
        duty: this.posInfo.duty.replace(/\n/g, '<br/>'),
        request: this.posInfo.request.replace(/\n/g, '<br/>'),
      }
    },
    toggleView () {
      this.showView = !this.showView;
    },
    cancel () {
      this.showView = !this.showView;
    },
    submit () {
      this.toCheck();
      this.showView = !this.showView;
      this.$emit('submit_desc', this.posInfo)
    }
  },
}
</script>

<style lang="scss" scoped>
.pos-desc {
  position: relative;

  .desc-title,
  .pos-title {
    color: #999;
    padding: 20px 0;
  }
  .desc {
    padding-left: 15px;
  }
  .desc-content,
  .pos-content {
    margin-bottom: 20px;
    p {
      color: #666;
      line-height: 32px;
    }
  }
  .com-form {
    padding: 30px 0;
    .upload {
      float: left;
      width: 350px;
      text-align: center;
      .img {
        height: 180px;
        width: 180px;
        margin: 0 auto;
        line-height: 180px;
        border: 1px solid #ebebeb;
        background: #ebebeb;
        border-radius: 50%;
        overflow: hidden;
        img {
          height: 100%;
          vertical-align: middle;
        }
        .seat {
          height: 100%;
          width: 100%;
          margin: 0;
          color: #999;
          cursor: pointer;
        }
      }
      .btn {
        color: #999;
        margin-top: 10px;
        &:hover {
          color: $base-color;
          cursor: pointer;
        }
      }
      .tips {
        font-size: 12px;
        color: #999;
        margin-top: 20px;
      }
    }
    .postForm {
      padding-left: 350px;
      .form-item {
        margin-bottom: 10px;
        line-height: 40px;
        & > div {
          display: inline-block;
        }
        & > .text {
          position: relative;
          padding-left: 20px;
          min-width: 120px;
          color: #24292f;
          vertical-align: top;
          &[required] {
            &::before {
              content: '*';
              position: absolute;
              left: 0px;
              top: 0px;
              color: $base-color-danger;
            }
          }
        }
        .input {
          input {
            line-height: 28px;
            border: 1px solid #ccc;
            border-radius: 4px;
            padding: 0 10px;
            width: 230px;
            font-size: 16px;
            &:active,
            &:focus {
              border-color: $base-color;
            }
          }
        }
        .label {
          label {
            margin-right: 30px;
          }
        }
        .select {
          ::v-deep .el-input__inner {
            width: 230px;
            height: 30px;
            line-height: 30px;
            border: 1px solid #ccc;
            font-size: 16px;
            color: #24292f;
            padding-right: 10px;
            &:active,
            &:focus {
              border-color: $base-color;
            }
          }
          &.small {
            ::v-deep .el-input__inner {
              width: 103px;
              padding-right: 20px;
              margin-right: 20px;
            }
            ::v-deep .el-input__suffix {
              right: 20px;
            }
          }
        }
        .textarea {
          margin-top: 10px;
          textarea {
            resize: none;
            height: 140px;
            width: 360px;
            border: 1px solid #ccc;
            border-radius: 4px;
            padding: 10px;
            color: #24292f;
            font-size: 16px;
            &:active,
            &:focus {
              border-color: $base-color;
            }
          }
          .count {
            text-align: right;
            span {
              color: $base-color;
              margin: 0 5px;
            }
          }
        }
      }
      .submit {
        margin-top: 60px;
        padding-left: 30px;
        text-align: left;
        button {
          height: 45px;
          width: 150px;
          margin: 0 20px;
          border: 1px solid $base-color;
          border-radius: 6px;
          font-size: 16px;
          &:hover {
            box-shadow: 0 0 6px 0 $base-color;
          }
        }
        .cancel {
          background: #fff;
          color: $base-color;
        }
        .confirm {
          background: $base-color;
          color: #fff;
        }
      }
    }
  }
}
</style>
